package com.kitty.game.fight.pet;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.Pair;
import com.kitty.game.utils.StatusConst;

/**
 * 乾坤罩
 * 对己方使用成功后，当被施法成员作为主目标受到物理攻击时，反弹对方的物理攻击。技能等级越高反弹的伤害越高
 */
public class QianKunZhaoProcessor extends PetSkillProcessor {

    @Override
    public void trigger(Fight fight, FightObject effector, FightObject target, int skillLevel, Object... args) {
        if (!fight.isSameSide(effector, target)) {
            return;
        }
        int round = skillLevel / 20;
        round = Math.max(round, 2);
        int status = bindingStatus();
        target.setStatus(status, round);
        target.setStatusScore(status, skillLevel);
    }

    @Override
    public Pair<Integer, Integer> effect(Fight fight, FightObject effector, FightObject target, Object... args) {
        int hurt = (int) args[0];
        int status = bindingStatus();
        if (!fight.isSameSide(effector, target)) {
            if (target.getStatusValue(status) >= 1) {
                // 乾坤罩技能等级*0.01 换算百分比 *攻击者伤害反弹给攻击者
                int backHurt = (int) (target.getStatusScore(status) * 0.01 * hurt);
                if (backHurt > effector.getCurrLife()) {
                    backHurt = effector.getCurrLife();
                }
                // 抵挡所有物理伤害
                hurt = 0;

                // 触发一次后移除
                target.removeStatus(status);
                return new Pair<>(hurt, backHurt);
            }
        }
        return new Pair<>(0, 0);
    }

    public int bindingStatus() {
        return StatusConst.STATUS_PASSIVE_ATTACK;
    }
}
